The crate name should be the package name, not `main`.
Closes #207
use ops;
use util::{CargoResult, human, process, ProcessError};
+use core::source::Source;
+use sources::PathSource;
pub fn run(manifest_path: &Path,
options: &mut ops::CompileOptions,
return Err(human("`src/main.rs` must be present for `cargo run`"))
}
+ let mut src = PathSource::for_path(&manifest_path.dir_path());
+ try!(src.update());
+ let root = try!(src.get_root_package());
+
try!(ops::compile(manifest_path, options));
- let exe = manifest_path.dir_path().join("target/main");
+ let exe = manifest_path.dir_path().join("target").join(root.get_name());
let exe = match exe.path_relative_from(&os::getcwd()) {
Some(path) => path,
None => exe,
use std::fmt;
use std::fmt::{Show,Formatter};
-use std::str;
use std::io::{UserDir};
use std::io::fs::{mkdir_recursive,rmdir_recursive};
use serialize::{Encodable,Encoder};
}
fn to_str(vec: &[u8]) -> String {
- str::from_utf8_lossy(vec).to_string()
+ String::from_utf8_lossy(vec).into_string()
}
#[deriving(Clone)]
pub struct Layout {
+ root: Path,
lib: Option<Path>,
bins: Vec<Path>,
examples: Vec<Path>,
try_add_files(&mut tests, root_path, "tests");
Layout {
+ root: root_path.clone(),
lib: lib,
bins: bins,
examples: examples,
fn inferred_bin_targets(name: &str, layout: &Layout) -> Option<Vec<TomlTarget>> {
Some(layout.bins.iter().filter_map(|bin| {
- let name = if bin.as_str() == Some("src/main.rs") {
+ let name = if bin.as_vec() == b"src/main.rs" ||
+ *bin == layout.root.join("src/main.rs") {
Some(name.to_string())
} else {
bin.filestem_str().map(|f| f.to_string())
-// use std::io::fs::{mkdir_recursive,rmdir_recursive};
-use std;
use std::io;
use std::io::fs;
use std::io::process::{ProcessOutput};
`{}`\n\n\
other output:\n\
`{}`", description, actual, out,
- str::from_utf8_lossy(extra)))
+ String::from_utf8_lossy(extra)))
}
}
}
-> ham::MatchResult
{
println!("{}", actual);
- let actual = std::str::from_utf8_lossy(actual);
+ let actual = String::from_utf8_lossy(actual);
let actual = actual.to_string();
ham::expect(actual == self.expected, actual)
}
execs().with_status(0));
assert_that(process(p.bin("release/foo")), execs().with_stdout("fast\n"));
})
+
+test!(inferred_main_bin {
+ let p = project("world")
+ .file("Cargo.toml", r#"
+ [project]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("src/main.rs", r#"
+ fn main() {}
+ "#);
+
+ assert_that(p.cargo_process("cargo-build"), execs().with_status(0));
+ assert_that(process(p.bin("foo")), execs().with_status(0));
+})
// TODO: -j1 is a hack
assert_that(foo.cargo_process("cargo-build").arg("-j").arg("1"),
execs().with_status(0));
- assert_that(&foo.bin("main"), existing_file());
- assert_that(foo.process(foo.bin("main")), execs().with_status(0));
+ assert_that(&foo.bin("foo"), existing_file());
+ assert_that(foo.process(foo.bin("foo")), execs().with_status(0));
})
test!(recompilation {
let target = alternate();
assert_that(p.cargo_process("cargo-build").arg("--target").arg(target),
execs().with_status(0));
- assert_that(&p.target_bin(target, "main"), existing_file());
+ assert_that(&p.target_bin(target, "foo"), existing_file());
assert_that(
- process(p.target_bin(target, "main")),
+ process(p.target_bin(target, "foo")),
execs().with_status(0));
})
let target = alternate();
assert_that(foo.cargo_process("cargo-build").arg("--target").arg(target),
execs().with_status(0));
- assert_that(&foo.target_bin(target, "main"), existing_file());
+ assert_that(&foo.target_bin(target, "foo"), existing_file());
assert_that(
- process(foo.target_bin(target, "main")),
+ process(foo.target_bin(target, "foo")),
execs().with_status(0));
})
let target = alternate();
assert_that(foo.cargo_process("cargo-build").arg("--target").arg(target),
execs().with_status(0));
- assert_that(&foo.target_bin(target, "main"), existing_file());
+ assert_that(&foo.target_bin(target, "foo"), existing_file());
assert_that(
- process(foo.target_bin(target, "main")),
+ process(foo.target_bin(target, "foo")),
execs().with_status(0));
})
assert_that(p.cargo_process("cargo-run"),
execs().with_status(0).with_stdout(format!("\
{compiling} foo v0.0.1 (file:{dir})
-{running} `target{sep}main`
+{running} `target{sep}foo`
hello
",
compiling = COMPILING,
running = RUNNING,
dir = p.root().display(),
sep = path::SEP).as_slice()));
- assert_that(&p.bin("main"), existing_file());
+ assert_that(&p.bin("foo"), existing_file());
})
test!(simple_with_args {
name = "foo"
version = "0.0.1"
authors = []
+
+ [[bin]]
+ name = "baz"
+ path = "src/main.rs"
"#)
.file("src/lib.rs", "
pub fn foo(){}
let head = format!("{compiling} foo v0.0.1 (file:{dir})",
compiling = COMPILING, dir = p.root().display());
+ println!("{}", out);
assert!(out == format!("{}\n\n{}\n\n\n{}\n\n", head, bin, lib).as_slice() ||
out == format!("{}\n\n{}\n\n\n{}\n\n", head, lib, bin).as_slice());
})
use support::{ResultTest,Tap,shell_writes};
use hamcrest::{assert_that};
use std::io::{MemWriter, BufWriter, IoResult};
-use std::str::from_utf8_lossy;
use cargo::core::shell::{Shell,ShellConfig};
use term::{Terminal,TerminfoTerminal,color};
try!(term.write_str(string.as_slice()));
try!(term.reset());
try!(term.flush());
- Ok(from_utf8_lossy(term.get_ref().get_ref()).to_string())
+ Ok(String::from_utf8_lossy(term.get_ref().get_ref()).to_string())
}